#coding=utf-8
import threading
from time import ctime,sleep
import serial
serialPort = raw_input("input serial port:<0~N>/n")
serialPort.replace(' ','')
serialPort = 'COM' + serialPort

ser = serial.Serial(serialPort,115200,timeout=5)
fd = open('c:/serialRead.txt','w')
def readSerialPort():
    while 1:
        count = ser.inWaiting()
        if count:
            #print "count:",count
            data=ser.read(count)
            fd.write(data)
            print data
            print ""
                
def writeSerialPort():
    while 1:
        data2send = raw_input("input data to send:/n")
        ser.write(data2send)
        
threads=[]
t1 = threading.Thread(target=readSerialPort)
threads.append(t1)
t2 = threading.Thread(target=writeSerialPort)
threads.append(t2)
if __name__=='__main__':
    for t in threads:
        t.setDaemon(True)
        t.start()
    t.join()
    print 'all over %s' % ctime()
    